<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>style属性演示</title>
    <style>
        input{
            display:block;
            width: 300px;
            height: 30px;
            margin:10px;
        }
        button{
            width: 100px;
            height: 50px;
            margin:10px;
            font:16px/50px microsoft yahei;
        }
    </style>
</head>
<body>
<ul>
    <input type="text">
    <input type="text">
    <input type="text">
    <input type="text">
    <input type="text">
    <button>设置</button>
</ul>

<script>
    //点击设置按钮，让所有的input标签获取焦点时高亮显示
    var inpArr=document.getElementsByTagName("input");
    var button=inpArr[inpArr.length-1].nextElementSibling||inpArr[inpArr.length-1].nextSibling;
    button.onclick=function(){
        for(var i=0;i<inpArr.length;i++){
            inpArr[i].onfocus=function(){
                this.style.border="2px solid red";
                this.style.backgroundColor="#ccc";
            }
            inpArr[i].onblur=function(){
                this.style.border="";
                this.style.backgroundColor="";
            }

        }
    }
</script>
</body>
</html>